<?php
 /*Template Name: Project
 */
 
get_header(); ?>

<div class="container" id="top_info">
	<div class="top-content">
	
    	<?php
			
			// Get project id
			$project_id = get_query_var('p_id');
			
			$original_id = $post->ID;
			
			$project_overview = get_post_meta($post->ID, 'dmci_project_overview', true); 
			$location_and_vicinity = get_post_meta($post->ID, 'dmci_location_vicinity', true);
			$building_features = get_post_meta($post->ID, 'dmci_building_features_and_plans', true);
			$unit_features = get_post_meta($post->ID, 'dmci_unit_features_and_plans', true);
			$amenities = get_post_meta($post->ID, 'dmci_amenities', true);
			
			$sliders = get_post_meta($post->ID, 'dmci_sliders', true);
			$slider_title = get_post_meta($post->ID, 'dmci_slider_title', true);
			$slider_desc = get_post_meta($post->ID, 'dmci_slider_desc', true);
			
			$active = '';
			
			
			
			
			if ( isset($wp_query->query_vars['location-vicinity'])){
				// get the location and vicinity
				$content = $location_and_vicinity;
				$active = 'location';
				
			}
			else if( isset($wp_query->query_vars['building-features']) ){
				$content = $building_features;
				$active = 'building';
			}
			else if( isset($wp_query->query_vars['unit-features']) ){
				$content = $unit_features;
				$active = 'unit';
			}
			else if ( isset($wp_query->query_vars['amenities']) ){
				$content = $amenities;
				$active = 'amenities';
			}
			else {
				$content = $project_overview;
				$active = 'project_overview';
			}
			
			$img = get_post_meta($post->ID, 'dmci_project_logo', true); 
			$imgH = get_post_meta($post->ID, 'logoHeight', true); 
			$imgW = get_post_meta($post->ID, 'logoWidth', true);
			
			if( $img ) {
				echo '<img src="'.$img.'" width="'.$imgW.'px" height="'.$imgH.'px" class="proj-logo" alt="'.get_the_title().' Logo"/>';	
			}
		?>	
			<ul class="proj-nav">
				
				<?php if( $project_overview ) :?> 
				<li>
					<a href="<?php echo the_permalink(); ?>" class="view-target <?php if( $active == 'project_overview' ){echo 'active';} ?>">
						<span class="arrow">></span>
						<span class="nav-text">Project Overview</span>
					</a>
				</li>
				<?php endif; ?>
				
				<?php if( $location_and_vicinity ) :?>
				<li>
					<a href="<?php echo the_permalink().'?location-vicinity'; ?>" class="view-target <?php if( $active == 'location' ){echo 'active';} ?>">
						<span class="arrow">></span>
						<span class="nav-text">Location and Vicinity</span>
					</a>
				</li>
				<?php endif; ?>
				
				<?php if( $building_features ) :?>
				<li>
					<a href="<?php echo the_permalink().'?building-features'; ?>" class="view-target <?php if( $active == 'building' ){echo 'active';} ?>">
						<span class="arrow">></span>
						<span class="nav-text">Building Features and Plans</span>
					</a>
				</li>
				<?php endif; ?>
				
				<?php if( $unit_features ) :?>
				<li>
					<a href="<?php echo the_permalink().'?unit-features'; ?>" class="view-target <?php if( $active == 'unit' ){echo 'active';} ?>">
						<span class="arrow">></span>
						<span class="nav-text">Unit Features and Plans</span>
					</a>
				</li>
				<?php endif; ?>
				
				<?php if( $amenities ) :?>
				<li>
					<a href="<?php echo the_permalink().'?amenities'; ?>" class="view-target <?php if( $active == 'amenities' ){echo 'active';} ?>">
						<span class="arrow">></span>
						<span class="nav-text">Amenities</span>
					</a>
				</li>
				<?php endif; ?>
				
				<?php 
				
				$query_args = array(
					'connected_type' => 'projects_to_consupdate',
					'post_type' => 'dmci_cons_update',
					'connected_direction' => 'to',
					'connected_its' => $post->ID,
					'nopaging' => true,
					'orderby' => 'title',
					'order' => 'ASC'
				);
				$project_query = new WP_Query($query_args);
				while( $project_query->have_posts() ) : $project_query->the_post();
					
					if( (int)$post->p2p_to == $original_id ) : ?>
					<li>
					
					<a href="<?php echo the_permalink() . '?p_id=' . $post->p2p_to; ?>" class="view-target">
						<span class="arrow">></span>
						<span class="nav-text">Construction Updates</span>
					</a>
					</li>
				<?php
					break;
					endif;	
				endwhile;			
				?>
					
			
			</ul>		
		<div class="clear">&nbsp;</div>
    </div>
    <div class="top-curve">&nbsp;</div>
</div>


<div class="container">
	<?php 
		
		if( $sliders ):
		$sliders = json_decode(htmlspecialchars_decode($sliders), true);
		
	?>
	<div class="page-slider-wrapper">
    <div class="page-slider">
		
		<?php foreach($sliders as $slide) :?>
        <div class="slide">
        	<img src="<?php echo $slide; ?>" alt="Image Slider" />
        </div>		
		<?php endforeach;?>
        
    </div>
	<div class="slider-text">
        <div class="title"><?php echo $slider_title; ?></div>
     	<div class="desc"><?php echo $slider_desc; ?></div>
    </div>
    </div>
	<?php else: ?>
		<div class="page-filler">&nbsp;</div>
	<?php endif; ?>
	
    
    <div class="page-content padded">
		<div class="view the-content">
    	<?php 
			echo apply_filters("the_content", $content);
		?>
        
        <div class="social">
	        <a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php echo get_permalink(); ?>" data-count="none" data-text="Check out <?php the_title(); ?> on < ?php bloginfo( 'name' ); ?>" data-via="cdharrison">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
        </div>
        
        <div class="social">
        	<?php echo do_shortcode('[facebook_like_button]'); ?>
        </div>
        
        
		</div>
        
        <div class="clear">&nbsp;</div>
	</div>
 
</div>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>